package org.ksug.samples.springmvc;

import java.beans.PropertyEditorSupport;

import org.springframework.util.StringUtils;

public class CountryEditor extends PropertyEditorSupport {

	private static final String MARKER = "-";

	@Override
	public void setAsText(String text) throws IllegalArgumentException {

		if(!StringUtils.hasText(text) || MARKER.equals(text))
			setValue(null);			
		
		for (Country country: Country.values()) {
			if(country.toString().equals(text))
				this.setValue(country);
		}
		
	}
}
